<?php

namespace Jobeet\Bundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jobeet\Bundle\Entity\Job;
use Jobeet\Bundle\Entity\CategoryRepository;
use Jobeet\Bundle\Form\Type\JobType;

class JobController extends Controller
{ 
    public function indexAction()
    {    
        $em = $this->getManager();
        $jobs = $em->getRepository('JobeetBundle:Job')->findAll();
        
        return $this->render('JobeetBundle:Job:index.html.twig', 
                              array('jobs' => $jobs) );
    }

    public function newAction()
    {    
        $job = new Job();
        $form = $this->createForm(new JobType(), $job);
        
        return $this->render('JobeetBundle:Job:new.html.twig', 
                            array('form' => $form->createView() ));
    }
    
    public function showAction($id)
    {
        $job = $this->getManager()->getRepository('JobeetBundle:Job')
                                 ->find($id);
        
        if(!$job)
        {
            throw $this->createNotFoundException('This Job does not exist');
        }
        
        return $this->render('JobeetBundle:Job:show.html.twig',
                              array('job' => $job) );        
    }
    
    public function editAction()
    {    
        return $this->render('JobeetBundle::layout.html.twig');
    }    
    
    private function getManager()
    {
        return $this->getDoctrine()->getEntityManager();
    }
}
